package cn.edu.cqupt.cxcy.action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.cqupt.cxcy.dto.AdminImpl;
import cn.edu.cqupt.cxcy.dto.IndexImpl;
import cn.edu.cqupt.cxcy.model.Tutor;
import cn.edu.cqupt.cxcy.util.Validate;


/**
 * 管理员后台主页
 * @author Dancer-mno
 * @date 2015年10月17日
 */
public class AdminAddTeacInfo extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		// /admin/addTeac
		String name  = request.getParameter("name");//用户名
		String loname  = request.getParameter("loname");//登陆名
		String tel = request.getParameter("tel");//电话
		String explain = request.getParameter("explain");//简介
		String no = request.getParameter("no");//电话
		int type = Validate.stringIsNO(request.getParameter("type"))?Integer.parseInt(request.getParameter("type")):0;
		if(loname!=null && !loname.equals("") && new IndexImpl().usernameIsUnique(loname)) {
			Tutor teac = new Tutor();
			teac.setTu_name(name);
			teac.setTu_loname(loname);
			teac.setTu_tel(tel);
			teac.setTu_explain(explain);
			teac.setTu_type(type);
			teac.setTu_NO(no);
			new AdminImpl().addTeac(teac);
		}
		response.sendRedirect(request.getHeader("referer"));
	}

}
